﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RzCorportativo.Lib;

namespace RzCorportativo.Views
{
    public partial class CursoCurriculo : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
                return;
            this.NomeCurso.Attributes.Add("url", this.ResolveUrl("~/Views/Cadastros/Curriculo.aspx/ListarCursos"));
            var lista = Lib.Formacao.Listar(new Lib.Formacao()
            {
                UsuarioId = (AppSession.Login.Usuario ?? new Lib.Usuario()).UsuarioId
            });
            foreach (var item in lista)
            {
                var row = new System.Web.UI.HtmlControls.HtmlTableRow();
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerText = (item.Curso ?? new Lib.Curso()).Nome
                });
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerText = item.Instituicao
                });
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerText = item.AnoInicio.ToString()
                });
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerText = item.AnoFim == 0 ? string.Empty : item.AnoFim.ToString()
                });
                row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                {
                    InnerHtml = "<input type='button' id='btnRemove" + item.FormacaoId.ToString() +
                    "' onclick='RemoveFormacao(" + item.FormacaoId.ToString() +
                    ", this)' class='btn btn-danger' value='remover'/>"
                });
                row.Attributes.Add("idioma", item.FormacaoId.ToString());
                this.gridFormacao.Rows.Add(row);
            }
        }
    }
}